import { Button, Tabs } from 'antd';
import React, { useCallback, useState } from 'react';
import MarkdownEditor from 'components/Editor';
const md = require('./index.md')
export default () => {
    const getResult = useCallback(() => {
        function test(result: number[] = []): number[] {
            if (result.length === 5) return result
            const number = Math.round(Math.random() * 32)
            if (result.includes(number) || number < 2 ) {
                return test(result)
            } else {
                return test(result.concat(number))
            }
        }
        return test()
    }, [])
    const [result, setResult] = useState('')
    const test = useCallback(() => {
        const res = getResult()
        setResult(JSON.stringify(res))
    }, [getResult])
    return (
        <div>
            用递归算法实现，数组长度为5且元素的随机数在2-32间不重复的值
            <Tabs>
                <Tabs.TabPane tab="运行" key="1">
                    <Button onClick={test}>获取结果</Button>
                    <div>{result}</div>
                </Tabs.TabPane>
                <Tabs.TabPane tab="代码" key="2">
                    <MarkdownEditor value={md.default} />
                </Tabs.TabPane>
            </Tabs>
        </div>
    )
}